package com.trace.app.controller;


import com.trace.app.entity.ResponseResult;
import com.trace.app.entity.User;
import com.trace.app.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户表(User)表控制层
 *
 * @author lionkliu
 * @since 2024-03-15 17:27:00
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return userService.selectPage(pageNum, pageSize);
    }


    @GetMapping("/getLabelValue")
    public ResponseResult getLabelValue() {
        return userService.getLabelValue();
    }


    @GetMapping("/search")
    public ResponseResult search(@RequestParam("pageNum") Integer pageNum,
                                 @RequestParam("pageSize") Integer pageSize,
                                 @RequestParam(value = "userType", required = false) Integer userType,
                                 @RequestParam(value = "username", required = false) String username) {
        return userService.search(pageNum, pageSize, userType, username);
    }

    @GetMapping("{id}")
    public ResponseResult selectOne(@PathVariable Integer id) {
        return userService.selectOne(id);
    }

    @PostMapping
    public ResponseResult insert(@RequestBody User user) {
        return userService.insertOne(user);
    }

    @PutMapping
    public ResponseResult update(@RequestBody User user) {
        return userService.updateOne(user);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return userService.deleteById(id);
    }

}
